package commons.base.grpc;

import java.net.InetSocketAddress;

import io.grpc.ManagedChannel;
import io.grpc.netty.NegotiationType;
import io.grpc.netty.NettyChannelBuilder;
import proto.rpc.RouteGuideGrpc;
import proto.rpc.Route.Hello;
import proto.rpc.RouteGuideGrpc.RouteGuideBlockingStub;

public class GrpcClient {

	public static void main(String[] args) {
		boolean useTls = false;
		ManagedChannel channel = NettyChannelBuilder.forAddress(new InetSocketAddress("127.0.0.1", 80))
	            .flowControlWindow(65 * 1024)
	            .negotiationType(useTls ? NegotiationType.TLS : NegotiationType.PLAINTEXT)
//	            .sslContext(sslContext)
	            .build();
		
		RouteGuideBlockingStub stub = RouteGuideGrpc.newBlockingStub(channel);
		Hello hello = stub.hello(Hello.newBuilder().setHello("client hello").build());
		System.err.println(hello.getHello());
		
		channel.shutdownNow();
	}

}
